home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: cs.vu.nl!jalten
- From: jalten@cs.vu.nl (Alten JP)
- Subject: Re: random number in C++
- Nntp-Posting-Host: kits.cs.vu.nl
- References: <4eoh03$6jb@pacemaker.cts>
- Sender: news@cs.vu.nl
- Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
- Date: Wed, 31 Jan 1996 23:09:58 GMT
- X-Newsreader: TIN [version 1.2 PL2]
- Message-ID: <DM2J0M.78J.0.-s@cs.vu.nl>
-
- Brian A. Bucher (babucher@mtu.edu) wrote:
-
- : Is there _ANY_ way to get a truly random number in a C++ program?
- : rand and srand do not generate random numbers, they generate
- : pseudo-random numbers, which is what I don't need.
-
- Get the date and time, cast them to a long,
- divide them by the number of bytes available on C:,
- add the number of printer ports and the state of COM1 (if on a PC),
- subtract the number of ticks it took to get that information
- and pump this into srand. Now ask the user to close his/her
- eyes and try to hit any key (or a number of keys) on the keyboard
- and take seven as the random number.
-
- Always works for me.
-
- Jelle Paul
-
- +-------------------------------------------------------+
- | Jelle Paul Alten | jalten@cs.vu.nl |
- | Vrije Universiteit Amsterdam | |
- +-------------------------------------------------------+
-